import cv2
# 读取图像
image = cv2.imread('images/demo2.png')
# 指定新的宽度和高度，使用 cv.INTER_LINEAR 插值进行放大
new_width = 200
new_height = 200
resized_image_linear = cv2.resize(image, (new_width, new_height), interpolation=cv2.INTER_LINEAR)
# 使用 cv.INTER_CUBIC 插值方法进行放大
resized_image_cubic = cv2.resize(image, (new_width, new_height), interpolation=cv2.INTER_CUBIC)
# 使用比例因子 0.5 对图像进行下采样，使用 cv.INTER_AREA 插值
scale_percent = 50  # 缩小 50%
width = int(image.shape[1] * scale_percent / 100)
height = int(image.shape[0] * scale_percent / 100)
resized_image_area = cv2.resize(image, (width, height), interpolation=cv2.INTER_AREA)
# 显示调整后的图像
cv2.imshow('Original Image', image)
cv2.imshow('Resized Image (Linear)', resized_image_linear)
cv2.imshow('Resized Image (Cubic)', resized_image_cubic)
cv2.imshow('Resized Image (Area)', resized_image_area)
# 等待按键退出
cv2.waitKey(0)
cv2.destroyAllWindows()
